package com.mcc.app.stock.controller;

import com.mcc.app.stock.domain.Silo;
import com.mcc.app.stock.service.ISiloService;
import com.mcc.common.annotation.Log;
import com.mcc.common.core.controller.BaseController;
import com.mcc.common.core.domain.AjaxResult;
import com.mcc.common.core.page.TableDataInfo;
import com.mcc.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 料仓Controller
 *
 * @author gxy
 * @date 2020-07-08
 */
@RestController
@RequestMapping("/silo/info")
public class SiloController extends BaseController {
    @Autowired
    private ISiloService siloService;

    /**
     * 查询料仓列表
     * @return
     */
    @GetMapping("/list")
    public AjaxResult<TableDataInfo<Silo>> list(Silo silo)
    {
      //  startPage();
        List<Silo> list = siloService.selectSiloList(silo);
        return getDataTable(list);
    }

    @GetMapping("/page")
    public AjaxResult<TableDataInfo<Silo>> page(Silo silo)
    {
        startPage();
        List<Silo> list = siloService.selectSiloList(silo);
        return getDataTable(list);
    }

    /**
     * 获取料仓详细信息
     */
    @GetMapping(value = "/{siloId}")
    public AjaxResult getInfo(@PathVariable("siloId") Long siloId)
    {
        return AjaxResult.success(siloService.selectSiloById(siloId));
    }

    /**
     * 新增料仓
     */
    @Log(title = "料仓", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Silo silo)
    {
        return toAjax(siloService.insertSilo(silo));
    }

    /**
     * 修改料仓
     */
    @Log(title = "料仓", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Silo silo)
    {
        return toAjax(siloService.updateSilo(silo));
    }

    /**
     * 删除料仓
     */
    @Log(title = "料仓", businessType = BusinessType.DELETE)
	@DeleteMapping("/{siloIds}")
    public AjaxResult remove(@PathVariable Long[] siloIds)
    {
        return toAjax(siloService.deleteSiloByIds(siloIds));
    }

    @PostMapping("/enableSilo")
    public AjaxResult enableSilo(@RequestBody Silo silo)
    {
        return toAjax(siloService.enableSilo(silo));
    }

    @GetMapping("/getOptionList")
    public AjaxResult<TableDataInfo<Silo>> getOptionList(Silo silo)
    {
        List<Silo> list = siloService.selectSiloList(silo);
        return getDataTable(list);
    }

    /**
     * 获取料仓历史数据
     * @param siloId
     * @param startDt
     * @param endDt
     * @return
     */
    @GetMapping("/getSiloDialog")
    public AjaxResult getSiloDialog(Long siloId, String startDt, String endDt) {
        return AjaxResult.success(siloService.getSiloDialog(siloId, startDt, endDt));
    }

    /**
     * 一混水分历史数据
     * @param startDt
     * @param endDt
     * @return
     */
    @GetMapping("/getMixingWaterVolume1Dialog")
    public AjaxResult mixingWaterVolume1Dialog(String startDt, String endDt) {
        return AjaxResult.success(siloService.mixingWaterVolume1Dialog(startDt, endDt));
    }

    /**
     * 二混水分历史数据
     * @param startDt
     * @param endDt
     * @return
     */
    @GetMapping("/getMixingWaterVolume2Dialog")
    public AjaxResult mixingWaterVolume2Dialog(String startDt, String endDt) {
        return AjaxResult.success(siloService.mixingWaterVolume2Dialog(startDt, endDt));
    }

    /**
     * 二总料量历史数据(实时)
     * @param startDt
     * @param endDt
     * @return
     */
    @GetMapping("/totalMaterialQuantityDialog")
    public AjaxResult totalMaterialQuantityDialog(String startDt, String endDt) {
        return AjaxResult.success(siloService.totalMaterialQuantityDialog(startDt, endDt));
    }

    /**
     * 获取供配料混合监控页面数值
     * @return
     */
    @GetMapping("/getMixedAttrValue")
    public AjaxResult getMixedAttrValue() {
        return AjaxResult.success(siloService.getMixedAttrValue());
    }

}
